import java.lang.instrument.Instrumentation;
import java.text.SimpleDateFormat

/**
 * 
 */

/**
 * @author hp
 *
 */
class Test {


	
	static main(args) {
/*
		def square = {it * it} // 定义一个叫square的闭包。it是默认的 参数名称
		assert 4 == square(2) // 使用闭包
		assert [1,4,9] == [1,2,3].collect(square) // 使用闭包
*/	


		
		def list = new ArrayList<Integer>();
		list.add(1);
		list.add(2);
		list.add(3);
		list.add(4);
		
		list.each {p it};
		
		// 委托模式
		def dog = new Dog()
		def cat = new Cat()
		dog.childmind()
		dog.childmind.delegate  = cat;
		dog.childmind()
	}

}

class Dog{
    def play = {
      "wang wang!"
    }
    def childmind = {
        println       delegate.play();      
    }
}
class Cat {
    def play = {"mi mi !"}
}


